package com.ferryc.controller;

import com.ferryc.entity.User;
import com.ferryc.model.Result;
import com.ferryc.service.IUserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.ResultType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * Created by Ferry Chen on 2019-11-06.
 */
@Api(tags = {"用户接口"})
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {


    @Autowired
    private IUserService userService;

    @ApiOperation(value = "用户列表",notes = "用户列表")
    @GetMapping(value = "/list",produces = MediaType.APPLICATION_JSON_VALUE)
    public Result<List<User>> queryUser() {
        return Result.success(userService.list());
    }

    @ApiOperation(value = "新增用户",notes = "新增用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "用户名称", required = true, dataType = "String"),
    })
    @PostMapping(value = "/add")
    public Result add(@RequestParam(value = "username") String username) {
        User u = new User();
        u.setUserName(username);
        userService.save(u);
        return Result.success("ok");
    }


}
